package mathFactsGUI;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

import javax.swing.*;
import javax.swing.border.Border;

import equations.AdditionStub;
import equations.DivisionStub;
import equations.FractionToDecimalStub;
import equations.Multiplication1Stub;
import equations.Multiplication2Stub;
import equations.SubtractionStub;

import accounts.Student;

/**
 * Creates a Graphic User Interface main menu for the Kumon MathFacts program
 * @author stewarte
 *
 */
public class GUI extends JFrame {
	
	/**
	 * app ID
	 */
	private static final long serialVersionUID = 7224310565796646304L;
	
	/**
	 * Array for holding GUI buttons that can be enabled or disabled, specifically, the test category buttons
	 */
	protected JButton[] buttons= null;
	
	/**
	 * Textfield for logging in with a given username
	 */
	protected JTextField usernameTextfield=null;
	
	/**
	 * textfield for user password
	 */
	protected JTextField passwordTextfield=null;
	
	/**
	 * Enter button for entering username and password information
	 */
	private JButton enterLoginInfo=null;
	
	/**
	 * JButton to activate hte staff login
	 */
	private JButton staffLogin=null;
	
	/**
	 * Button to logout the user
	 */
	private JButton logOut=null;
	
	/**
	 * Button for creating a new user
	 */
	private JButton newUser=null;
	
	/**
	 * Name of the currently logged in user
	 */
	protected String logInName=null;
	
	/**
	 * Student object
	 */
	protected Student student=null;
	
	/**
	 * The temporary name 
	 */
	protected String tempName=null;
	
	/**
	 * This color corresponds with kumon's blue color
	 */
	protected final Color kumonBlue= new Color(103,238,255);
	
	/**
	 * This color will correspond to each of the button's colors, ultimately defines their gradient
	 */
	protected final Color buttonBlue = new Color(0,162,232);
	
	/**
	 * This is the font used whenever we want arial text
	 */
	protected final Font arial=new Font("Arial", Font.PLAIN, 26);
	
	/**
	 * This is the default black border wherever a border is used
	 */
	private Border blackBoarder = BorderFactory.createLineBorder(Color.BLACK, 4);
	
	/**
	 * This is the border used universally for buttons
	 */
	private Border buttonBorder = BorderFactory.createLineBorder(Color.BLACK, 2);
	
	/**
	 * This is the jframe representing a new user.
	 */
	protected JFrame newUserFrame;
	
	/**
	 * Arraylist of students who are allowed to login
	 */
	private ArrayList<Student> studentsLogin = new ArrayList<Student>();
	
	/**
	 * Creates the main menu
	 */
	public  GUI(){
		
		/**
		 * For future release, 
		 * don't change now in prototype
		 * , we need to make our layouts liquid, no fixed dimensions,
		 *  calculate pixels based on screen size.
		 */
		// Set up our window
		this.setTitle("Kumon Math Facts");
		//set window dimensions fixed dimensions for prototype
		this.setSize(1024,728);
		//closing GUI is disabled, we don't want kids to just exit
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		//fixed size for prototype
		this.setResizable(false);
		//this.setUndecorated(true);
		this.setLocationRelativeTo(null);
		
		this.setUndecorated(true);
		
		JPanel backdrop = new JPanel();
		ImageIcon backgroundImage = new ImageIcon("images\\kumon_app_background.png");
		JLabel backgroundComp = new JLabel(backgroundImage);
		backgroundComp.setBounds(0,0,backgroundImage.getIconWidth(),backgroundImage.getIconHeight());
		this.getLayeredPane().add(backgroundComp,new Integer(Integer.MIN_VALUE));
		backdrop.setOpaque(false);
		this.setContentPane(backdrop);	
		backdrop.setBorder(buttonBorder);
		
		
		// Creates components to for the main window
		ImageIcon kumonHeader = new ImageIcon("images\\header.png");
		JLabel kumonLogo= new JLabel(kumonHeader);
		kumonLogo.setBorder(blackBoarder);
		
		JPanel north = new JPanel();
		north.setOpaque(false);
		JPanel center=new JPanel();
		center.setOpaque(false);
		JPanel west= new JPanel();
		//west.setOpaque(false);
		center.setLayout(new GridLayout(0,2, 20, 20));
		west.setLayout(new GridBagLayout());
		
		//Creates components for the center panel
		JButton addition= new JButton("Addition");
		addition.addActionListener(new AL());
		addition.setBorder(buttonBorder);
		JButton subtraction= new JButton("Subtraction");
		subtraction.addActionListener(new AL());
		subtraction.setBorder(buttonBorder);
		JButton multiplication1= new JButton("Multiplication I");
		multiplication1.addActionListener(new AL());
		multiplication1.setBorder(buttonBorder);
		JButton multiplication2= new JButton("Multiplication II");
		multiplication2.addActionListener(new AL());
		multiplication2.setBorder(buttonBorder);
		JButton division = new JButton("Division");
		division.addActionListener(new AL());
		division.setBorder(buttonBorder);
		JButton decFrac = new JButton("Fractions to Decimals");
		decFrac.addActionListener(new AL());
		decFrac.setBorder(buttonBorder);

		GridBagConstraints c= new GridBagConstraints();
		
		//Creates components for the West Panel
		c.anchor=(GridBagConstraints.FIRST_LINE_START);
		c.insets= new Insets(0,10,5,0);

		
		JLabel login = new JLabel("Username: ");
		
		c.gridx=0;
		c.gridy=1;
		
		west.add(login,c);
		
		
		usernameTextfield= new JTextField(9);
		
		c.gridx=0;
		c.gridy=2;
		c.ipadx=0;
		c.insets= new Insets(0,10,5,10);
		
		west.add(usernameTextfield,c);
		
		JLabel passwordLine = new JLabel("Password:");
		c.gridy=3;
		west.add(passwordLine,c);
		
		passwordTextfield = new JPasswordField(9);
		c.gridx=0;
		c.gridy=4;
		c.ipadx=0;
		c.insets = new Insets(0,10,5,5);
		west.add(passwordTextfield,c);
		
		enterLoginInfo = new JButton("Login");
		
		c.ipadx=35;
		c.gridx=0;
		c.gridy=5;
		enterLoginInfo.addActionListener(new AL());
		
		west.add(enterLoginInfo,c);
		
		logOut = new JButton("Log Out");
		
		logOut.addActionListener(new AL());
		c.ipadx=22;
		c.gridx=0;
		c.gridy=6;
		
		west.add(logOut,c);
		logOut.setEnabled(false);
		
		newUser = new JButton("New User");
		newUser.addActionListener(new AL());
		c.gridy=7;
		c.ipadx=11;
		west.add(newUser, c);
		
		staffLogin= new JButton("Manage Acc.");
		staffLogin.addActionListener(new AL());
		staffLogin.setMargin(new Insets(3,8,2,8)); 
		staffLogin.setEnabled(false);
		
		c.ipadx=5;
		c.gridx=0;
		c.gridy=8;
		
		west.add(staffLogin,c);
		
		JTextArea blankarea= new JTextArea();
		blankarea.setSize(20,100);
		blankarea.setEnabled(false);
		blankarea.setOpaque(false);
		c.ipady=385;
		c.gridx=0;
		c.gridy=8;
		
		west.add(blankarea,c);
		west.setBackground(kumonBlue);
		
		//Creates a container for all JButton components
		buttons= new JButton[]{addition, subtraction, multiplication1, multiplication2, division, decFrac};
		
		//Deactivates buttons that should not be active
		enableButtons(false);
		
		//Adds components to the center panel
		center.add(addition);
		center.add(subtraction);
		center.add(multiplication1);
		center.add(multiplication2);
		center.add(division);
		center.add(decFrac);
		//center.setBorder(blueBorder);
		//center.setBackground(kumonBlue);
		
		
		north.add(kumonLogo);
		west.setOpaque(false);
		north.setBackground(kumonBlue);
		
		
		//Adds components to main window
		backdrop.setLayout(new BorderLayout());
		backdrop.add(north,BorderLayout.NORTH);
		backdrop.add(center, BorderLayout.CENTER);
		backdrop.add(west, BorderLayout.WEST);
		
		File loginNames = new File("profiles\\UserData\\LogInInfo\\accounts.txt");
		
		//Populates the arraylist of students
		try {
			Scanner scanLoginFile = new Scanner(loginNames);
			
				while(scanLoginFile.hasNextLine()){
					Student stud = new Student(scanLoginFile.nextLine(),scanLoginFile.nextLine(),scanLoginFile.nextLine(),scanLoginFile.nextLine());
					studentsLogin.add(stud);
					scanLoginFile.nextLine();
				}
				
		} catch (FileNotFoundException e) {
			JOptionPane.showMessageDialog(null, "A Fatal Error has Occurred when generating Login information. Please reinstall the program");
		}
		//this.add(backdrop);
		this.setVisible(true);
		
		
	}//End GUI constructor
	
	/**
	 * Enables all buttons or disables depending on Boolean Input
	 * @param enable
	 */
	public void enableButtons(Boolean enable){
		
		
		
		if (enable ==false){
			
			for(int i =0; i<buttons.length; i++){
				buttons[i].setEnabled(false);
				buttons[i].setFont(arial);
				buttons[i].revalidate();
				}//end for
		
		}else if (enable){
			
			for(int i =0; i<buttons.length; i++){
				
				buttons[i].setEnabled(true);
				buttons[i].setForeground(Color.black);
				buttons[i].setFont(arial);
				buttons[i].revalidate();
				}//end for
			
		}//end if enable
		
		
	}//end Enable Buttons
	
	/**
	 * Method that get's the time in the format of year/month/day hours:minutes:seconds (military time)
	 * @return String Date
	 */
    private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }
    
    /**
     * Validates the log in information
     * @param username
     * @param password
     * @return
     */
    private boolean loginSearch(String username, String password){
    	boolean loginSuccess = false;
    	//searches each student in studentsLogin and checks to see that the login information is accurate
    	for(Student s: studentsLogin){
    		
    		if(s.getName().equals(username)&&s.getPassword().equals(password)){
    			loginSuccess=true;
    		}
    	}
    	return loginSuccess;
    }
	
	/**
	 * Action Listener for the buttons in the GUI
	 * @author stewarte
	 *
	 */
	private class AL implements ActionListener{

		
		//GUI Components for the new entry GUI
		private JTextField usernameEntry;
		private JTextField passwordEntry;
		private JTextField firstNameEntry;
		private JTextField lastNameEntry;
		private JTextField retypeEntry;
		private JLabel username;
		private JLabel passwordLabel;
		private JLabel retypePassword;
		private JLabel firstName;
		private JLabel lastName;

		@Override
		public void actionPerformed(ActionEvent ae) {
			if(ae.getSource() instanceof JButton){
				//Enter button
				if(ae.getActionCommand()=="Login"){
					//gets the username from the user and assigns it to tempname
					tempName=usernameTextfield.getText();
					logInName=tempName;
					
					
					
					//Checks to see that there is text
					
					if(tempName.equals("Admin")){
						staffLogin.setEnabled(true);
					}//End if Admin
					
					//if a valid log in name
					if(loginSearch(tempName,passwordTextfield.getText())){
						enableButtons(true);
						logOut.setEnabled(true);
						enterLoginInfo.setEnabled(false);
						newUser.setEnabled(false);
					}//End if confirmLogin
					
					//if entry is empty
					else if(tempName.length()==0){
						JOptionPane.showMessageDialog(null,"Please type in your name before pressing login");
					}//if the login information does not match and is not empty
					else{
						JOptionPane.showMessageDialog(null, "Login information is invalid. Please create a new account");
					}
					

					
					
				}//End if button enter
				
				//Log Out button
				
				//if the user logs out, resets the name box, disables all buttons, reenables the enter button
				if(ae.getActionCommand()=="Log Out"){
					usernameTextfield.setText("");
					passwordTextfield.setText("");
					enableButtons(false);
					enterLoginInfo.setEnabled(true);
					newUser.setEnabled(true);
					logOut.setEnabled(false);
				}
				
				//Multiplication I Button
				if(ae.getActionCommand()=="Multiplication I"){
					enableButtons(false);
					Multiplication1Stub mult= new Multiplication1Stub();
					@SuppressWarnings("unused")
					Quizzer multiplication = new Quizzer(mult);
					/**TODO: Replace this logic with SQL*/
					File outputFile = new File("MathFacts_scores\\"+tempName+".txt");
					Quizzer.output=null;
					try {
						Quizzer.output=new PrintWriter(new FileWriter(outputFile, true));
						Quizzer.output.println(getDateTime());
						Quizzer.output.println("Name: "+ tempName);
						Quizzer.output.println("Category: Multiplication I");

					} catch (IOException ioe){
						ioe.printStackTrace();
					}
				}//End if Multiplication I
				
				//Multiplication II Button
				if(ae.getActionCommand()=="Multiplication II"){
					enableButtons(false);
					Multiplication2Stub mult2= new Multiplication2Stub();
					@SuppressWarnings("unused")
					Quizzer multiplication2 = new Quizzer(mult2);

					/**TODO: Replace this logic with SQL*/
					File outputFile = new File("MathFacts_scores\\"+tempName+".txt");
					Quizzer.output=null;
					try {
						Quizzer.output=new PrintWriter(new FileWriter(outputFile, true));
						Quizzer.output.println(getDateTime());
						Quizzer.output.println("Name: "+ tempName);
						Quizzer.output.println("Category: Multiplication II");

					} catch (IOException ioe){
						ioe.printStackTrace();
					}
				}//End if Multiplication II
				
				//Addition Button
				if(ae.getActionCommand()=="Addition"){
					enableButtons(false);
					AdditionStub add= new AdditionStub();
					@SuppressWarnings("unused")
					Quizzer addition = new Quizzer(add);

					/**TODO: Replace this logic with SQL*/
					File outputFile = new File("MathFacts_scores\\"+tempName+".txt");
					Quizzer.output=null;
					try {
						Quizzer.output=new PrintWriter(new FileWriter(outputFile, true));
						Quizzer.output.println(getDateTime());
						Quizzer.output.println("Name: "+ tempName);
						Quizzer.output.println("Category: Addition");

					} catch (IOException ioe){
						ioe.printStackTrace();
					}
				}//End if Addition
				
				//Subtraction Button
				if(ae.getActionCommand()=="Subtraction"){
					enableButtons(false);
					SubtractionStub sub= new SubtractionStub();
					@SuppressWarnings("unused")
					Quizzer subtraction = new Quizzer(sub);

					/**TODO: Replace this logic with SQL*/
					File outputFile = new File("MathFacts_scores\\"+tempName+".txt");
					Quizzer.output=null;
					try {
						Quizzer.output=new PrintWriter(new FileWriter(outputFile, true));
						Quizzer.output.println(getDateTime());
						Quizzer.output.println("Name: "+ tempName);
						Quizzer.output.println("Category: Subtraction");

					} catch (IOException ioe){
						ioe.printStackTrace();
					}
				}//End if Subtraction
				
				//Division Button
				if(ae.getActionCommand()=="Division"){
					enableButtons(false);
					DivisionStub div= new DivisionStub();
					@SuppressWarnings("unused")
					Quizzer multiplication = new Quizzer(div);

					/**TODO: Replace this logic with SQL*/
					File outputFile = new File("MathFacts_scores\\"+tempName+".txt");
					Quizzer.output=null;
					try {
						Quizzer.output=new PrintWriter(new FileWriter(outputFile, true));
						Quizzer.output.println(getDateTime());
						Quizzer.output.println("Name: "+ tempName);
						Quizzer.output.println("Category: Division");

					} catch (IOException ioe){
						ioe.printStackTrace();
					}
				}//End if Division
				
				//Fractions to Decimals button
				if(ae.getActionCommand()=="Fractions to Decimals"){
					enableButtons(false);
					FractionToDecimalStub frac= new FractionToDecimalStub();
					@SuppressWarnings("unused")
					Quizzer multiplication = new Quizzer(frac);

					/**TODO: Replace this logic with SQL*/
					File outputFile = new File("MathFacts_scores\\"+tempName+".txt");
					Quizzer.output=null;
					try {
						Quizzer.output=new PrintWriter(new FileWriter(outputFile, true));
						Quizzer.output.println(getDateTime());
						Quizzer.output.println("Name: "+ tempName);
						Quizzer.output.println("Category: Fractions to Decimals");

					} catch (IOException ioe){
						ioe.printStackTrace();
					}
				}//End if Fractions to Decimals
				
				if(ae.getActionCommand()=="Manage Acc."){
					JFrame staffLogin= new JFrame();
					staffLogin.setLocationRelativeTo(null);
					staffLogin.setSize(400,600);
					staffLogin.setVisible(true);
					staffLogin.setDefaultCloseOperation(EXIT_ON_CLOSE);
					staffLogin.setTitle("Manage Acc.");
					staffLogin.setLayout(new BorderLayout(3,3));
					
					JTextArea directions = new JTextArea("More Options coming soon...");
					directions.setFont(arial);
					
					JButton exit= new JButton("Exit");
					exit.addActionListener(new ActionListener(){
						@Override
						public void actionPerformed(ActionEvent arg0) {
							System.exit(0) ;
						}
					});
					staffLogin.add(directions, BorderLayout.CENTER);
					staffLogin.add(exit,BorderLayout.SOUTH);
				}
				if(ae.getActionCommand()=="New User"){
					
					newUser.setEnabled(false);
					newUserFrame = new JFrame();
					newUserFrame.setSize(350,425);
					
					JPanel mainPanel = new JPanel();
					JPanel topPanel = new JPanel();
					JPanel backPanel = new JPanel();
					
					backPanel.setLayout(new BorderLayout());
					topPanel.setLayout(new GridBagLayout());
					mainPanel.setLayout(new GridBagLayout());
					
					GridBagConstraints c = new GridBagConstraints();
					c.anchor=GridBagConstraints.PAGE_START;
					
					//Gives directions on correct username
					JLabel directions = new JLabel("Let's create an account, Please enter your");
					c.gridx=0;
					c.gridy=0;
					topPanel.add(directions,c);
					
					JLabel directions2 = new JLabel("last name with the first initial of");
					c.gridx=0;
					c.gridy=1;
					topPanel.add(directions2,c);
					
					JLabel directions3 = new JLabel("your first name as your username.");
					c.gridy=2;
					topPanel.add(directions3,c);
					
					JLabel blankLine = new JLabel(" ");
					c.gridy=3;
					topPanel.add(blankLine, c);
					
					JLabel directions4 = new JLabel("Next, choose any password that you like.");
					c.gridy=4;
					topPanel.add(directions4,c);
					
					JLabel blankLine2 = new JLabel(" ");
					c.gridy=5;
					topPanel.add(blankLine2,c);
					
					JLabel directions5 = new JLabel("Finally, enter your first and last name");
					c.gridy=6;
					topPanel.add(directions5,c);
					
					JLabel directions6 = new JLabel("and then press the 'Create Account' button.");
					c.gridy=7;
					topPanel.add(directions6,c);
					
					username = new JLabel("Username:  ");
					c.anchor=GridBagConstraints.NORTHWEST;
					c.gridx=0;
					c.gridy=2;
					c.insets=new Insets(20,5,0,5);
					c.weightx=.1;
					mainPanel.add(username,c);
					
					usernameEntry = new JTextField(9);
					c.gridx=1;
					c.weightx=.5;
					c.ipadx=15;
					mainPanel.add(usernameEntry,c);
					
					passwordLabel = new JLabel("Password: ");
					c.gridx =0;
					c.gridy=3;
					mainPanel.add(passwordLabel,c);
					
					passwordEntry = new JPasswordField(9);
					c.gridx=1;
					
					mainPanel.add(passwordEntry,c);
					
					retypePassword = new JLabel("Retype password: ");
					c.gridx=0;
					c.gridy=4;
					mainPanel.add(retypePassword, c);
					
					retypeEntry = new JPasswordField(9);
					c.gridx=1;
					mainPanel.add(retypeEntry,c);
					
					
					firstName = new JLabel("First Name: ");
					c.gridx =0;
					c.gridy=5;
					mainPanel.add(firstName,c);
					
					firstNameEntry = new JTextField(9);
					c.gridx = 1;
					mainPanel.add(firstNameEntry,c);
					
					lastName = new JLabel("Last Name: ");
					c.gridx=0;
					c.gridy=6;
					mainPanel.add(lastName,c);
					
					lastNameEntry = new JTextField(9);
					c.gridx=1;
					c.gridy=6;
					mainPanel.add(lastNameEntry, c);
					
					JButton createAccount = new JButton("Create Account");
					
					c.gridx=0;
					c.gridy=7;
					mainPanel.add(createAccount,c);
					
					JButton cancel = new JButton("Cancel");
					c.gridx=1;
					c.gridy=7;
					mainPanel.add(cancel,c);
					
					
					backPanel.add(topPanel,BorderLayout.NORTH);
					backPanel.add(mainPanel,BorderLayout.CENTER);
					
					
					ActionListener al = new ActionListener(){

						@Override
						public void actionPerformed(ActionEvent ae) {
							if(ae.getActionCommand()=="Create Account"){
								
								//checks to see if the username has already been used previously
								boolean validUserName = true;
								String userConfirm = usernameEntry.getText();
								for(Student s: studentsLogin){
									if(userConfirm.equals(s.getName())){
										validUserName=false;
									}
								}
								
								//if the username is empty
								if(usernameEntry.getText().equals(null)||usernameEntry.getText().equals("")){
									JOptionPane.showMessageDialog(null, "Please type in a user name");
									username.setForeground(Color.red);
									username.setText("*Username: ");
								}
								
								//in the event that the username has already been used
								else if(validUserName==false){
									JOptionPane.showMessageDialog(null,"Username invalid, there is already an account with that name");
								}
								
								//if the password is empty
								else if(passwordEntry.getText().equals(null)||passwordEntry.getText().equals("")){
									JOptionPane.showMessageDialog(null, "Please type in a password");
									passwordLabel.setForeground(Color.red);
									passwordLabel.setText("*Password: ");
									username.setForeground(Color.black);
									username.setText("Username: ");
								}
								
								//if the retype is empty
								else if(retypeEntry.getText().equals(null)||retypeEntry.getText().equals("")){
									JOptionPane.showMessageDialog(null, "Please retype your password");
									retypePassword.setForeground(Color.red);
									retypePassword.setText("*Retype Password: ");
									passwordLabel.setForeground(Color.black);
									passwordLabel.setText("Password: ");
									}
								
								//if the first name is empty
								else if(firstNameEntry.getText().equals(null)||firstNameEntry.getText().equals("")){
									JOptionPane.showMessageDialog(null, "Please type in your first name");
									firstName.setForeground(Color.red);
									firstName.setText("*First Name: ");
									retypePassword.setForeground(Color.black);
									retypePassword.setText("Retype Password: ");	
								}
								
								//if the last name is empty
								else if(lastNameEntry.getText().equals(null)||lastNameEntry.getText().equals("")){
									JOptionPane.showMessageDialog(null, "Please type in your last name");
									lastName.setForeground(Color.red);
									lastName.setText("*Last Name: ");
									firstName.setForeground(Color.black);
									firstName.setText("First Name: ");
								}
								//if the passwords do not match
								else if(!(passwordEntry.getText().equals(retypeEntry.getText()))){
									JOptionPane.showMessageDialog(null, "Your entries do not match, please make sure that you are typing them in correctly");
								}
								//if all form conditions are met, proceeds with adding the student
								else{
								
								String userNameString = usernameEntry.getText();
								String passwordString = passwordEntry.getText();
								String firstNameString = firstNameEntry.getText();
								String lastNameString = lastNameEntry.getText();
								
								try{
									File accounts = new File("profiles\\UserData\\LogInInfo\\Accounts.txt");
									PrintWriter output=new PrintWriter(new FileWriter(accounts, true));
									output.println(userNameString);
									output.println(passwordString);
									output.println(firstNameString);
									output.println(lastNameString);
									output.println("***");
									output.close();
									newUserFrame.dispose();
									newUser.setEnabled(true);
								}catch(Exception ioe){
									System.out.println("Couldnt find file");
								}
								
								//adds the new student to the current list of students log in information
								Student newStud = new Student(userNameString,passwordString,firstNameString,lastNameString);
								studentsLogin.add(newStud);
								
							}//end else everything is ok
								
							}else if(ae.getActionCommand()=="Cancel"){
								newUserFrame.dispose();
								newUser.setEnabled(true);
							}//end else if action command
							
						}//end action performed
						
					};
					cancel.addActionListener(al);
					createAccount.addActionListener(al);
					
					newUserFrame.add(backPanel);
					newUserFrame.setLocationRelativeTo(null);
					newUserFrame.setVisible(true);
					
				}

			}//End if source JButton
			
		}//End ActionPerformed
		
	}//End ActionListener


}//End GUI Class
